using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

// 学习链接: https://zhuanlan.zhihu.com/p/77641752
// https://catlikecoding.com/unity/tutorials/scriptable-render-pipeline/custom-pipeline/

/// <summary>
/// 自定义渲染管线
/// </summary>
public class CustomRenderPipeline : RenderPipeline
{
    // 自定义管线的具体渲染逻辑

    CustomRenderPipelineAsset customRenderPipeline;
    /// <summary>
    /// 创建自定义管线
    /// </summary>
    public CustomRenderPipeline(CustomRenderPipelineAsset pipelineAsset)
    {
        this.customRenderPipeline = pipelineAsset;
    }

    /// <summary>
    /// 重新管线的绘制
    /// </summary>
    /// <param name="context"></param>
    /// <param name="cameras"></param>
    protected override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        // ScriptableRenderContext对象，它充当着C#代码与Unity底层图形代码的接口
        // cameras[] 各种视图下的摄像机 

        // 2.2 相机
        //context.DrawSkybox(cameras[0]);
        //context.Submit();

        // SetupCameraProperties 设置相机的属性到上下文中? 就是什么意思呢？
        //context.SetupCameraProperties(cameras[0]);
        //context.DrawSkybox(cameras[0]);
        //context.Submit();

        // 2.3 命令缓存
        // 命令缓冲可以被实例化一个新的CommandBuffer对象所创建

        // ClearRenderTarget
        // ExecuteCommandBuffer

        var cmd = new CommandBuffer{name = cameras[0].name };
        cmd.ClearRenderTarget(true, true, customRenderPipeline.clearColor);
        context.ExecuteCommandBuffer(cmd);
        cmd.Release();
        context.Submit();

        // 2.4 剔除
        //ScriptableCullingParameters

    }
}
